package com.xiao.mall.example.service;

import com.xiao.mall.client.message.dto.UserDto;
import com.xiao.mall.example.domain.User;
import com.xiao.mall.example.repository.UserRepository;
import com.xiao.mall.example.service.criteria.UserCriteria;
import com.xiao.mall.example.service.mapper.UserMapper;
import com.xiao.mall.foundation.service.Criteria;
import com.xiao.mall.foundation.service.CurdService;
import com.xiao.mall.foundation.service.SpecificationHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

/**
 * 用户信息实现类
 * @Auther tangzhihui
 * @Date 2021/9/17
 */
@Service
@Slf4j
public class UserService extends CurdService<User, UserDto, Integer> {

    private final UserRepository repository;
    private final UserMapper mapper;

    public UserService(UserRepository repository, UserMapper mapper) {
        super(repository, mapper);
        this.repository = repository;
        this.mapper = mapper;
    }


    @Override
    protected Specification<User> createSpecification(Criteria criteria) {
        UserCriteria userCriteria = (UserCriteria) criteria;
        return SpecificationHelper.create(User.class)
//                .buildSpecification(UserCriteria.getOperatorId(), User_.operatorId)
//                .buildStringSpecification(UserCriteria.getOperatorName(), User_.operatorName)
//                .buildRangeSpecification(UserCriteria.getOperationDate(), User_.operationDate)
//                .buildSpecification(UserCriteria.getOperationMethod(), User_.operationMethod)
                .build();
    }
}
